package svc

import (
	"github.com/zeromicro/go-zero/rest"
	"github.com/zeromicro/go-zero/zrpc"
	"test-demo/api/internal/config"
	"test-demo/api/internal/middleware"
	"test-demo/goods_srv/goodsclient"
	"test-demo/user_srv/userclient"
)

type ServiceContext struct {
	Config      config.Config
	AuthToken   rest.Middleware
	UserServer  userclient.User
	GoodsServer goodsclient.Goods
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:      c,
		AuthToken:   middleware.NewAuthTokenMiddleware().Handle,
		UserServer:  userclient.NewUser(zrpc.MustNewClient(c.UserServer)),
		GoodsServer: goodsclient.NewGoods(zrpc.MustNewClient(c.GoodsServer)),
	}
}
